<template>
    <div>
        <!-- 添加备注弹框 -->
        <uni-popup ref="popup" type="dialog">
            <uni-popup-dialog
                mode="input"
                :title="title"
                :placeholder="placeholder"
                v-model="iptValue"
                @confirm="confirm"
                @close="closePopup"
            ></uni-popup-dialog>
        </uni-popup>

    </div>
</template>

<script setup lang="ts">
import {ref, reactive } from "vue"
import interact from "@/utils/interact"
const popup = ref()
const refundRemark = ref('')
const currentItem = ref<any>(null)

type PEOptions = {
    title: string,
    placeholder: string,
    iptValue?: string
    required?: boolean
}

const title = ref('')
const placeholder = ref('')
const iptValue = ref('')
const required = ref(false)
let promiseResolve: Function | null = null

const open = async (options: PEOptions) => {
    return new Promise((resolve, reject) => {
        promiseResolve = resolve
        iptValue.value = options.iptValue || ''
        title.value = options.title
        required.value = options.required || false
        placeholder.value = options.placeholder
        popup.value.open()
    })
}

const closePopup = () => {
    popup.value.close()
    currentItem.value = null
    refundRemark.value = ''
}

const confirm = () => {
    if(required.value && !iptValue.value) {
        interact.toast(placeholder.value)
        return false
    }
    (promiseResolve as Function)(iptValue.value)
    closePopup()
}

defineExpose({
    open
})
</script>
<style lang="less" scoped>

</style>